package main

import (
	"fmt"
	. "whoops/leetcode/common"
)

//#link: https://leetcode-cn.com/problems/leaf-similar-trees/
func main() {

}

var (
	nodeList1 []int
	nodeList2 []int
)

func leafSimilar(root1 *TreeNode, root2 *TreeNode) bool {
	nodeList1 = make([]int, 0)
	getLeafNodes(root1, true)
	nodeList2 = make([]int, 0)
	getLeafNodes(root2, false)
	fmt.Println(nodeList1, nodeList2)
	if len(nodeList1) != len(nodeList2) {
		return false
	}
	for i := 0; i < len(nodeList1); i++ {
		if nodeList1[i] != nodeList2[i] {
			return false
		}
	}
	return true
}

func getLeafNodes(root *TreeNode, isOk bool) {
	if root != nil {
		getLeafNodes(root.Left, isOk)
		if root.Left == nil && root.Right == nil {
			if isOk {
				nodeList1 = append(nodeList1, root.Val)
			} else {
				nodeList2 = append(nodeList2, root.Val)
			}
		}
		getLeafNodes(root.Right, isOk)
	}
}

type Queue struct {
	Nums []*TreeNode
}

func (q *Queue) push(node *TreeNode) {
	if len(q.Nums) == 0 {
		q.Nums = make([]*TreeNode, 0)
	}
	q.Nums = append(q.Nums, node)
}

func (q *Queue) pop() *TreeNode {
	node := q.Nums[0]
	q.Nums = q.Nums[1:]
	return node
}
